package com.hyt.it.ogt.kq.main.controller.gov;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.it.ogt.kq.common.gov.config.swagger.ApiVersionConstant;
import com.hyt.it.ogt.kq.common.gov.constant.ResponseCode;
import com.hyt.it.ogt.kq.service.gov.arrange.ProctorArrangeFactory;
import com.hyt.it.ogt.kq.service.gov.model.param.proctor.AutoProctorParam;
import com.hyt.it.ogt.kq.service.gov.model.param.proctor.ManualProctorParam;
import com.hyt.it.ogt.kq.service.gov.model.param.proctor.ProctorParam;
import com.hyt.it.ogt.kq.service.gov.model.param.proctor.ProctorRoomSearchParam;
import com.hyt.it.ogt.kq.service.gov.model.vo.examiner.*;
import com.hyt.it.ogt.kq.service.gov.service.IProctorService;
import com.hyt.log.annotation.Log;
import com.hyt.progress.creator.anno.ProgressAnno;
import com.hyt.swagger.ApiVersion;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiSort;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "41.监考员编排接口", value = "监考员编排接口")
@ApiSort(value = 41)
@RequestMapping("/kw/gov/proctor/arrange")
@Slf4j
public class ProctorController {
    @Resource
    private IProctorService iProctorService;
    @Resource
    private ProctorArrangeFactory proctorArrangeFactory;

    @ApiOperation(value = "41.1 监考员编排统计查询", response = ProctorArrangeResultVO.class)
    @ApiOperationSort(value = 1)
    @ApiVersion(group = ApiVersionConstant.V2_4_10)
    @GetMapping(value = "/getProctorArrangeResult")
    public ApiResponse<ProctorArrangeResultVO> getProctorArrangeResult(@RequestParam String taskId) {
        return ApiResponse.<ProctorArrangeResultVO>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .data(iProctorService.getProctorArrangeResult(taskId))
                .build();
    }

    @ApiOperation(value = "41.2 监考员考场查询", response = ProctorArrangeResultVO.class)
    @ApiOperationSort(value = 2)
    @ApiVersion(group = ApiVersionConstant.V2_4_10)
    @GetMapping(value = "/getProctorRoom")
    public ApiResponse<Page<ProctorArrangeRoomVO>> getProctorRoom(Page<ProctorArrangeRoomVO> page, ProctorRoomSearchParam param) {
        return ApiResponse.<Page<ProctorArrangeRoomVO>>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .data(iProctorService.getProctorRoom(page, param))
                .build();
    }

    @ApiOperation(value = "41.3 手动编排监考员")
    @ApiOperationSort(value = 3)
    @ApiVersion(group = ApiVersionConstant.V2_4_10)
    @PostMapping(value = "/manualProctorArrange")
    public ApiResponse manualProctorArrange(@RequestBody ManualProctorParam param) {
        iProctorService.manualProctorArrange(param);
        return ApiResponse.builder()
                .code(ResponseCode.SUCCESS.getCode())
                .build();
    }

    @ApiOperation(value = "41.4 自动编排监考员")
    @ApiOperationSort(value = 4)
    @ApiVersion(group = ApiVersionConstant.V2_4_10)
    @Log(module = "监考员编排管理", business = "自动编排监考员")
    @PostMapping(value = "/autoProctorArrange")
    @ProgressAnno(timeoutSeconds = 10 * 60, errorCode = 43410401, canConcurrent = false)
    public void autoProctorArrange(@RequestBody AutoProctorParam param) {
        proctorArrangeFactory.arrange(param);
    }

    @ApiOperation(value = "41.5 重置监考员编排")
    @ApiOperationSort(value = 5)
    @ApiVersion(group = ApiVersionConstant.V2_4_10)
    @PostMapping(value = "/resetProctorArrange")
    public ApiResponse resetProctorArrange(@RequestParam String taskId) {
        iProctorService.resetProctorArrange(taskId);
        iProctorService.resetArrange(taskId);
        return ApiResponse.builder()
                .code(ResponseCode.SUCCESS.getCode())
                .build();
    }

    @ApiOperation(value = "41.6 监考员编排参数查询", response = TimeRoomParamVO.class)
    @ApiOperationSort(value = 6)
    @ApiVersion(group = ApiVersionConstant.V2_4_10)
    @GetMapping(value = "/getProctorParam")
    public ApiResponse<List<TimeRoomParamVO>> getProctorParam(@RequestParam String taskId) {
        return ApiResponse.<List<TimeRoomParamVO>>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .data(iProctorService.getProctorParam(taskId))
                .build();
    }

    @ApiOperation(value = "41.6 重置监考员编排参数")
    @ApiOperationSort(value = 6)
    @ApiVersion(group = ApiVersionConstant.V2_4_10)
    @PostMapping(value = "/initProctorParam")
    public ApiResponse initProctorParam(String taskId) {
            iProctorService.initProctorParam(taskId);
        return ApiResponse.builder()
                .code(ResponseCode.SUCCESS.getCode())
                .build();
    }

    @ApiOperation(value = "41.9 查询条件-考点", response = ProctorCommonResponseTemplateVO.class)
    @ApiOperationSort(value = 9)
    @ApiVersion(group = ApiVersionConstant.V2_4_10)
    @GetMapping(value = "/getPlace")
    public ApiResponse<List<ProctorCommonResponseTemplateVO>> getPlace(@RequestParam String taskId, int arrangeState) {
        return ApiResponse.<List<ProctorCommonResponseTemplateVO>>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .data(iProctorService.getPlace(taskId, arrangeState))
                .build();
    }

    @ApiOperation(value = "41.10 查询条件-考场", response = ProctorCommonResponseTemplateVO.class)
    @ApiOperationSort(value = 10)
    @ApiVersion(group = ApiVersionConstant.V2_4_10)
    @GetMapping(value = "/getRoom")
    public ApiResponse<List<ProctorCommonResponseTemplateVO>> getRoom(@RequestParam String taskId, @RequestParam String placeId, @RequestParam int arrangeState) {
        return ApiResponse.<List<ProctorCommonResponseTemplateVO>>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .data(iProctorService.getRoom(taskId, placeId, arrangeState))
                .build();
    }

    @ApiOperation(value = "41.11 查询条件-批次", response = ProctorCommonResponseTemplateVO.class)
    @ApiOperationSort(value = 11)
    @ApiVersion(group = ApiVersionConstant.V2_4_10)
    @GetMapping(value = "/getTime")
    public ApiResponse<List<ProctorCommonResponseTemplateVO>> getTime(@RequestParam String taskId, @RequestParam int arrangeState) {
        return ApiResponse.<List<ProctorCommonResponseTemplateVO>>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .data(iProctorService.getTime(taskId, arrangeState))
                .build();
    }

    @ApiOperation(value = "41.12 锁定监考员编排")
    @ApiOperationSort(value = 12)
    @ApiVersion(group = ApiVersionConstant.V2_4_10)
    @GetMapping(value = "/lockProctorArrange")
    public ApiResponse lockProctorArrange(@RequestParam String taskId, @RequestParam boolean lockState) {
        iProctorService.lockProctorArrange(taskId, lockState);
        return ApiResponse.builder()
                .code(ResponseCode.SUCCESS.getCode())
                .build();
    }

    @ApiOperation(value = "41.13 导出监考员编排")
    @ApiOperationSort(value = 13)
    @ApiVersion(group = ApiVersionConstant.V2_4_10)
    @GetMapping(value = "/downloadProctorArrange")
    @ProgressAnno(total = 100, timeoutSeconds = 600)
    public void downloadProctorArrange(@RequestParam String taskId) {
        iProctorService.downloadProctorArrange(taskId);
    }

    @ApiOperation(value = "41.14 监考员查询列表")
    @ApiOperationSort(value = 14)
    @ApiVersion(group = ApiVersionConstant.V2_4_10)
    @GetMapping(value = "/getProctor")
    public ApiResponse<List<ProctorVO>> getProctor(ProctorParam param) {
        return ApiResponse.<List<ProctorVO>>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .data(iProctorService.getProctor(param))
                .build();
    }
}
